#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>

using namespace std;

class Solution
{
public:
    vector<int> intersection(vector<int> &nums1, vector<int> &nums2)
    {
        vector<int> nums(1001, 0);
        vector<int> r;
        for (auto it = nums1.begin(); it != nums1.end(); it++)
            nums[*it] = 1;
        for (auto it = nums2.begin(); it != nums2.end(); it++)
        {
            if (nums[*it] == 1)
                nums[*it] = -1;
        }
        for (size_t i = 1; i < nums.size(); i++)
        {
            if (nums[i] == -1)
                r.push_back(i);
        }
        return r;
    }

    // 用哈希表实现
    vector<int> intersection(vector<int> &nums1, vector<int> &nums2)
    {
        unordered_set<int> result_set; // 存放结果，之所以用set是为了给结果集去重
        unordered_set<int> nums_set(nums1.begin(), nums1.end());
        for (int num : nums2)
        {
            // 发现nums2的元素 在nums_set里又出现过
            if (nums_set.find(num) != nums_set.end())
                result_set.insert(num);
        }
        return vector<int>(result_set.begin(), result_set.end());
    }
};

int main()
{

    return 0;
}
